﻿using System;
using System.Collections.Generic;
using System.Text;

namespace FeCMS.UrlRoute
{
    /// <summary>
    ///     规则
    /// </summary>
    internal class MapRoute
    {

        #region 单列

        static MapRoute instance = null;
        static readonly object padLock = new object();
        /// <summary>
        /// 单件模式返回此类
        /// </summary>
        public static MapRoute Instance
        {
            get
            {
                lock (padLock)
                {
                    if (instance == null)
                    {
                        instance = new MapRoute();
                    }
                }
                return instance;
            }
        }

        #endregion

        #region 私有变量

        private string[] _urlRult;

        private int _len;

        private RoutePack[] _RoutePacks;

        #endregion

        #region 构造函数

        private void MapRoute()
        {
            //TODO:实现规则的读取与整理
        }

        #endregion

        #region 公有方法

        /// <summary>
        ///     返回Map索引
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public string GetUrlRule(int index)
        {
            return _urlRult[index];
        }

        /// <summary>
        ///     获取到Map路由
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public IRoutePack GetRoutePack(int index)
        {
            return _RoutePacks[index];
        }

        #endregion

        #region 属性

        /// <summary>
        ///     索引长度
        /// </summary>
        public int IndexLen
        {
            get
            {
                return _len;
            }
        }

        #endregion


        private class RoutePack : IRoutePack
        {

            public string Controller
            {
                get;
                set;
            }

            public string Action
            {
                get;
                set;
            }

            public string TemplatePath
            {
                get;
                set;
            }

            public Common.Enum.ControllerType ControllerType
            {
                get;
                set;
            }

            public Data.TemplateDataSoure DataSoure
            {
                get;
                set;
            }
        }
    }
}
